/* TCSS 590A - Cybernetics and Systems
 * Group Project - Modeling
 * By Barry Jones, Naren Meadem, Michael Pitts, Yuan Tao
 * Fall 2012, University of Washington, Tacoma
 */
package model.delayed.tactical;

import model.delayed.Event;


/**
 * A NegotiableGenerator that requires a certain amount of time between 
 * negotiations if they are to succeed.  Also limits the magnitude of the change 
 * to an Event's value to the original value, meaning no more than double and no 
 * less than zero.
 * @author Michael Pitts
 * @version Dec 3, 2012
 */
public abstract class RareNegGenerator extends NegotiableGenerator
{
	
	/** Is the minimum time between negotiations that this negotiator will allow.*/
	private final int my_time_between_neg;
	
	/** The last negotiation time.*/
	private long my_last_negotiation;
	
	/**
	 * Creates a new RareNegGenerator which will require that the time between 
	 * negotiations be at least the value indicated and the change in the Event's
	 * value not exceed the absolute value of the original Event.
	 * @param the_time_between is how long you must wait between negotiations.
	 */
	public RareNegGenerator(final int the_time_between)
	{
		my_time_between_neg = the_time_between;
		my_last_negotiation = -my_time_between_neg - 1;
	}

	@Override public boolean negotiate(final Event the_event, final long the_change)
	{
		if (my_last_negotiation + my_time_between_neg > the_event.time ||
				Math.abs(the_change) > Math.abs(the_event.value)) 
			return false;
		my_last_negotiation = the_event.time;
		return true;
	}

}
